#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    long long N;
    string S, T;
    cin >> N >> S >> T;

    // Step 1: Count frequencies of characters in S and T
    vector<int> freqS(26, 0), freqT(26, 0);
    for (char c : S) freqS[c - 'a']++;
    for (char c : T) freqT[c - 'a']++;

    // Step 2: Adjust frequencies for f(S, N)
    for (int &f : freqS) f *= N;

    // Step 3 and 4: Calculate and find the minimum k across all characters in T
    long long k = LLONG_MAX;
    for (int i = 0; i < 26; ++i) {
        if (freqT[i] > 0) {
            k = min(k, freqS[i] / freqT[i]);
        }
    }

    cout << k << endl;
    return 0;
}

